import Vue from 'vue'
import VueRouter from 'vue-router'
import { routers, appRouter } from './router'
import Util from '@/utils/util'
import store from "../store/index" //vuex
Vue.use(VueRouter)
const RouterConfig = {
    // mode: 'history',
    routes: routers
};
export const router = new VueRouter(RouterConfig);

router.beforeEach((to, from, next) => {
    Util.panduan();
    let fullPath = to.fullPath;
    let user = localStorage.getItem('token');
    if (to.name == "Login") {
        if (user == null || user == "" || user == undefined) {
            next();
        } else {
            next("/index");
        }
    } else {
        if (user == null || user == "" || user == undefined) {

            sessionStorage.setItem("relUrl", fullPath); //添加
            next("/login");
        } else {

          next();


        }
    }
})
router.afterEach((to) => {
    if (!to.name == "Login") {
        Util.openNewPage(router.app, to.name, to.params, to.query);
        // iView.LoadingBar.finish();
        window.scrollTo(0, 0);
    }
});

// export default router;